package com.aaa.car.service.impl;

import com.aaa.car.dao.TbMaintainShopDao;
import com.aaa.car.entity.TbMaintainShop;
import com.aaa.car.service.TbMaintainShopService;
import com.aaa.common.constant.ReturnCode;
import com.aaa.common.util.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * (TbMaintainShop)表服务实现类
 *
 * @author makejava
 * @since 2020-11-18 23:03:31
 */
@Service("tbMaintainShopService")
public class TbMaintainShopServiceImpl implements TbMaintainShopService {
    @Resource
    private TbMaintainShopDao tbMaintainShopDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TbMaintainShop queryById(Integer id) {
        return this.tbMaintainShopDao.queryById(id);
    }

    @Override
    public Result queryAllMaintainShop(Integer pageNo, Integer pageSize, TbMaintainShop tbMaintainShop) {
        //分页
        PageHelper.startPage(pageNo,pageSize);
        PageInfo<TbMaintainShop> pageInfo = new PageInfo<TbMaintainShop>(tbMaintainShopDao.queryAll(tbMaintainShop));
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),pageInfo);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<TbMaintainShop> queryAllByLimit(int offset, int limit) {
        return this.tbMaintainShopDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param tbMaintainShop 实例对象
     * @return 实例对象
     */
    @Override
    public TbMaintainShop insert(TbMaintainShop tbMaintainShop) {
//        //设置日期格式
//        SimpleDateFormat updateTime = new SimpleDateFormat("yyyy-MM-dd");
        // new Date()为获取当前系统时间
        tbMaintainShop.setAddtime(new Date());
        this.tbMaintainShopDao.insert(tbMaintainShop);
        return tbMaintainShop;
    }

    /**
     * 修改数据
     *
     * @param tbMaintainShop 实例对象
     * @return 实例对象
     */
    @Override
    public TbMaintainShop update(TbMaintainShop tbMaintainShop) {
        this.tbMaintainShopDao.update(tbMaintainShop);
        return this.queryById(tbMaintainShop.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.tbMaintainShopDao.deleteById(id) > 0;
    }
}